<template>
    <div>
         <mt-swipe :auto="2000" style=" height:370px;">
        <mt-swipe-item v-for="item in imglist" :key="item.index">
          <img :src="item" style="width:100%; height:100%;">
        </mt-swipe-item>
      </mt-swipe>
           <div class="money">
            <div class="box_title">{{goodsName}}</div>
            <div class="box_bom">
                <span>￥{{goodsScreenPrice}}</span>
                <span> 库存{{goodsstock}}</span>
            </div>
           </div>
         
        
        <div class="box_msg">
            <div>
            <span>规格</span>
            <span>暂无规格</span>
            </div>
            <div>
                <span>参数</span>
                <span>暂无参数</span>
            </div>
        </div>

        <div style="margin-bottom:50px;">
             <img src="../../assets/personal/images/shangpinxiangqing_02.png">
             <ul>
                 <li v-for="ins in msimg" :key="ins.index">
                    <img :src="ins" alt="">
                 </li>
             </ul>
        </div>
        <div class="bombtn">
            <router-link to @click.native="quxiao()">取消</router-link>
             <router-link to @click.native="ylfabu()">发布</router-link>
        </div>

    </div>
</template>

<script>
import { Switch, Swipe, SwipeItem } from "mint-ui";
export default {
    components:{
        [Switch.name]: Switch,
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem
    },
      data() {
        return {
            imglist:[],
            goodsName:'',
            goodsstock:'',
            goodsid:'',
            companyid:'',
            imgfengmian:'',
            lmid:'',
            goodsScreenPrice:'',
            goodsexprice:'',
            mstext:'',
            shouhou:'',
            cityname:'',
            msimg:[],
            entrance:'',
            lesid:'',
            aftersalesTYPE:''
        }
      },
      mounted(){
        this.info()
      },
      methods:{
          info(){
           this.imglist=JSON.parse(sessionStorage.getItem('topimg'))
           console.log(sessionStorage.getItem('goodsid'))
           this.msimg=JSON.parse(sessionStorage.getItem('lastimg'))
           this.lesid=sessionStorage.getItem('goodsid')
           this.entrance=this.$route.query.entrance
           console.log(this.msimg)
           this.goodsName=this.$route.query.goodsName
           this.goodsstock=this.$route.query.goodsstock
           this.goodsid=this.$route.query.goodsid
           this.companyid=this.$route.query.companyid
           this.imgfengmian=this.$route.query.imgfengmian
           this.lmid=this.$route.query.lmid
           this.aftersalesTYPE=this.$route.query.aftersalesTYPE
           this.goodsScreenPrice=this.$route.query.goodsScreenPrice
           this.goodsexprice=this.$route.query.goodsexprice
           this.mstext=this.$route.query.mstext
           this.shouhou=this.$route.query.shouhou
           this.cityname=this.$route.query.cityname
           console.log(this.goodsstock)
           console.log(this.imglist,this.goodsName,this.goodsstock,this.companyid,this.goodsid,this.imgfengmian,this.lmid,this.goodsScreenPrice,this.goodsexprice,this.mstext,this.shouhou,this.cityname)
          },
          ylfabu(){
          console.log(this.lesid)
           var lodimg=this.msimg.join(',')
           var arrimg=this.imglist.join(',')
               if(this.lesid==''||this.lesid=='undefined'||this.lesid==null){
                   console.log('发布商品')
                    
                 this.$http
                .post(this.APIURL_PREFIX + "/api/wap/createGoods",
                $.param({goodsThum:this.imgfengmian,cateId:this.lmid,isMaterial:this.aftersalesTYPE,goodsScreenPrice:this.goodsScreenPrice*100,goodsStock:this.goodsStock,goodsExPrice:this.goodsexprice*100,detaileDescription:this.mstext,isAfterSale:this.shouhou,deliveryPlace:this.cityname,goodsProviderId:this.companyid,goodsOnline:1,goodsName:this.goodsName})
                    
                )
                .then(response=>{
                console.log(response)
                var goodsid=response.data.data.goodsId
                if(response.data.code==0){
                    this.$http
                .post(this.APIURL_PREFIX + "/api/wap/goodsAlbum/create",
                $.param({imgUrl:arrimg,detailePictureUrl:lodimg,imageType:1,goodsId:goodsid,goodsProviderId:this.companyid}))
                    .then(response=>{
                    console.log(response)
                    if(response.data.code==0){
                        sessionStorage.clear()
                        this.$router.push({name:'me_goods'})
                    }
                    })
                }
                })


               }else{
                   console.log('编辑商品')
                    this.$http
                .put(this.APIURL_PREFIX + "/api/wap/updateGoods",
                $.param({goodsId:this.lesid,imgUrl:arrimg,detailePictureUrl:lodimg,isMaterial:this.aftersalesTYPE,goodsThum:this.imgfengmian,cateId:this.lmid,goodsScreenPrice:this.goodsScreenPrice,goodsStock:this.goodsstock,goodsExPrice:this.goodsexprice,detaileDescription:this.mstext,isAfterSale:this.shouhou,deliveryPlace:this.cityname,goodsOnline:1,goodsName:this.goodsName})
                )
                .then(response => {
                    console.log(response)
                    if(response.data.code==0){
                        sessionStorage.clear()
                        this.$router.push({name:'me_goods'})
                    }
                  })
               }
          },
         quxiao(){
             this.$router.push({path:'me_newgoods',query:{goodsid:this.goodsid,companyid:this.companyid}})
         }
      }
};
</script>

<style scoped>
@import "../../assets/personal/css/me_goodsyulan.css";
</style>
